package cate.game.play.buff.h;

import cate.common.table.d.GDPlay;
import cate.game.play.base.HpCfg;
import cate.game.play.buff.BuffHandler;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.fighter.Fighter;
import cate.game.play.proce.action.ctx.ActionCtx;
import easy.java.struct.ref.DoubleRef;

/**
 * 受到攻击时反弹20%的伤害，反弹伤害不超过妲己最大生命值的18%,并将反弹伤害的50%转化为治疗量
 */
public class 反伤BH extends BuffHandler {

	private double 系数;

	private HpCfg 最大值配置;

	private double 治疗系数;

	//系数=2000&最大值配置=1:1:1:1&
	//治疗系数=？？
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		系数 = args.getWDouble("系数", 0d);
		最大值配置 = new HpCfg(args,"最大值配置");
		治疗系数 = args.getWDouble("治疗系数", 0d);
	}

	@Override
	public void parseExt(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		治疗系数 += args.getWDouble("治疗系数", 0d);
	}

	@Override
	public void adjustSkillDamage(ActionCtx action, Fighter actor, int reason, DoubleRef doubleRef) {
		double rebound = doubleRef.v * 系数;
		double max = 最大值配置.settle(actor, buff.owner);
		if (max > 0) {
			rebound = Math.min(max, rebound);
		}
		actor.attr.buffHurt(action, buff.owner, rebound);
		if (治疗系数 > 0) {
			buff.owner.attr.buffHeal(action, buff.owner, doubleRef.v * 治疗系数);
		}
	}
}
